package tw.chen.unlock;

import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.IBinder;
import android.util.Log;

public class WidgetService extends Service
{
	private String TAG = this.getClass().getName();
	
	IntentFilter filter;

	@Override
	public void onCreate() 
	{
		Log.i(TAG, "service create...");
		filter = new IntentFilter();
		filter.addAction(Values.SCREEN_OFF);
		filter.addAction(Values.SCREEN_ON);
		registerReceiver(mReceiver, filter);
		
		super.onCreate();
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) 
	{
		Log.i(TAG, "service start...");
		return super.onStartCommand(intent, flags, startId);
	}
	
	private BroadcastReceiver mReceiver = new BroadcastReceiver()
	{
		@Override
		public void onReceive(Context arg0, Intent intent) 
		{
			String action = intent.getAction();
			if (action.equals(Values.SCREEN_OFF))
			{
				Log.i(TAG, "screen off......");
			}
			if (action.equals(Values.SCREEN_ON))
			{
				Log.i(TAG, "screen on.....");
				Intent activity = new Intent(getBaseContext(), TransparentActivity.class);
				activity.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				getApplication().startActivity(activity);
			}
		}
	};

	@Override
	public void onDestroy() 
	{
		Log.i(TAG, "service destroy...");
		unregisterReceiver(mReceiver);
		
		super.onDestroy();
	}

	@Override
	public IBinder onBind(Intent arg0) 
	{
		return null;
	}
}
